/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.itschapala.dsw2.bar.bl.BebidaBlLocal;
import mx.itschapala.dsw2.bar.modelo.Bebida;

/**
 *
 * @author Dhavis
 */
@ManagedBean
@SessionScoped
public class BebidaBean {

    @EJB
    private BebidaBlLocal bebidaBl;
    //------------------variables(propiedades)--------------
    private List<Bebida> lista;
    private Bebida drink;
    private String accion;
    //-----------constructor--------------------------------

    public BebidaBean() {
        drink = new Bebida();
    }
    //-----------metodos GET y SET--------------------------------

//    public List<DetalleVenta> getLista() {
//        lista = drink.getAll();
//        return lista;
//    }

    public Bebida getDrink() {
        return drink;
    }

    public void setDrink(Bebida drink) {
        this.drink = drink;
    }
    //-----------Acciones--------------------------------

//    public String procesarAccion() {
//        if (accion.equalsIgnoreCase("Nuevo")) {
//            bebidaBl.register(drink);
//        } else if (accion.equalsIgnoreCase("Editar")) {
//            bebidaBl.register(drink);
//        } else if (accion.equalsIgnoreCase("Eliminar")) {
//            bebidaBl.delete(drink);
//        }
//        accion = " ";
//        return "BebidaVista";
//    }

    public String prepararAutor() {
        drink.setIdBebida(Integer.SIZE);
        return "BebidaConfirmar";
    }

    //-----------Listeners--------------------------------   
    public void prepararNuevo(ActionEvent evt) {//accionEvent de faces
        drink = new Bebida();
        accion = "Nuevo";
    }

    public void prepararEditar(ActionEvent evt) {
        System.out.println(evt.getComponent().getClientId());
        String arr[] = evt.getComponent().getClientId().split(":");
        String num = arr[3];
        int index = Integer.parseInt(num);
        System.out.println("el numero es------------->>>>>>: " + index);
        drink = lista.get(index);
        accion = "Editar";
    }
    public void prepararEliminar(ActionEvent evt){
        String arr[]=evt.getComponent().getClientId().split(":");
        String num=arr[3];
        int index=Integer.parseInt(num);
        System.out.println("el numero es: "+index);
        drink=lista.get(index);
        accion="Eliminar";
    }   
}